home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / imc9103.zip / MOUSE3.C < prev    next >
Text File  |  1991-03-05  |  3KB  |  88 lines

  1. /****************************************************************
  2. *    MOUSE3.C -- Demonstration program for third mouse article      *
  3. *                                                                                     *
  4. *    To compile:    cl mouse3.c /link graphics                                 *
  5. ****************************************************************/
  6.  
  7. #include <conio.h>        /* getch()                                        */
  8. #include <dos.h>            /* int86(), REGS                                */
  9. #include <graph.h>        /* _clearscreen(), _GCLEARSCREEN()        */
  10. #include <stdio.h>        /* printf()                                        */
  11. #include <stdlib.h>        /* exit(), EXIT_FAILURE                        */
  12. #include <string.h>        /* memset(), strset()                        */
  13.  
  14. void main(void)
  15.     {
  16.     char scr_string[41];
  17.     int i, top, bottom, left, right, row, col, number_times;
  18.     union REGS in_regs, out_regs;
  19.  
  20.     in_regs.x.ax = 0;           /* Initialize mouse */
  21.     int86(0x33, &in_regs, &out_regs);
  22.     if (!out_regs.x.ax)
  23.         {
  24.         printf("Mouse could not be initialized.\n");
  25.         exit(EXIT_FAILURE);
  26.         }
  27.  
  28.     _clearscreen(_GCLEARSCREEN);
  29.  
  30.     in_regs.x.ax = 1;           /* Show mouse cursor */
  31.     int86(0x33, &in_regs, &out_regs);
  32.  
  33.     /* Draw a box on the screen */
  34.     memset(scr_string,205,40);
  35.     scr_string[0] = 201;
  36.     scr_string[39] = 187;
  37.     scr_string[40] = 0;
  38.     printf("%s\n", scr_string);
  39.  
  40.     strset(scr_string, 32);
  41.     scr_string[0] = 186;
  42.     scr_string[39] = 186;
  43.     for (i = 0; i < 10; i++)
  44.         printf("%s\n", scr_string);
  45.  
  46.     strset(scr_string, 205);
  47.     scr_string[0] = 200;
  48.     scr_string[39] = 188;
  49.     printf("%s\n\n\n", scr_string);
  50.  
  51.     printf("\nPress a key to restrict mouse cursor to the box.");
  52.     getch();
  53.  
  54.     right = 39;         /* Restrict cursor horizontally */
  55.     left = 2;
  56.     in_regs.x.cx = 8 * (right - 1);
  57.     in_regs.x.dx = 8 * (left - 1);
  58.     in_regs.x.ax = 7;
  59.     int86(0x33, &in_regs, &out_regs);
  60.  
  61.     top = 2;            /* Restrict cursor vertically */
  62.     bottom = 11;
  63.     in_regs.x.cx = 8 * (top - 1);
  64.     in_regs.x.dx = 8 * (bottom - 1);
  65.     in_regs.x.ax = 8;
  66.     int86(0x33, &in_regs, &out_regs);
  67.  
  68.     in_regs.x.bx = 0;   /* Clear left button queue */
  69.     in_regs.x.ax = 5;
  70.     int86(0x33, &in_regs, &out_regs);
  71.     printf(    "\nPress the left mouse button a few times,"
  72.             " then any key.");
  73.     getch();
  74.  
  75.     in_regs.x.bx = 0;   /* Read left button queue */
  76.     in_regs.x.ax = 5;
  77.     int86(0x33, &in_regs, &out_regs);
  78.  
  79.     number_times = out_regs.x.bx;
  80.     row = out_regs.x.dx / 8 + 1;
  81.     col = out_regs.x.cx / 8 + 1;
  82.     printf("\nYou pressed it %d times.", number_times);
  83.     printf("\nLast time at (%d, %d).", row, col);
  84.  
  85.     in_regs.x.ax = 2;   /* Hide mouse cursor */
  86.     int86(0x33, &in_regs, &out_regs);
  87.     }
  88.